/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipo.mm.web.formbeans;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.ipo.mm.ejb.entities.City;

/**
 *
 * @author makcro
 */
public class CityBean extends org.apache.struts.validator.ValidatorForm {

    private String name;
    private String zipCode;
    private String note;
    private String submit;

    /**
     *
     */
    public CityBean() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = super.validate(mapping, request);

        return errors;
    }

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {

        String method = request.getParameter("method");

        if ("showUpdateCityForm".equals(method)) {
            City city = (City) request.getSession().getAttribute("updateCity.city");

            this.setName(city.getName());
            this.setZipCode(city.getZipCode());
            this.setNote(city.getNote());

        }



    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {

//        try {
//            if (name != null) {
//                // this.name = new String(name.getBytes(ConstantManager.ENCODING_ISO88591), ConstantManager.ENCODING_UTF8);
//                this.name = new String(name.getBytes(ConstantManager.ENCODING_UTF8), ConstantManager.ENCODING_UTF8);
//            }
//
//            // this.name = name;
//        } catch (UnsupportedEncodingException ex) {
//            Logger.getLogger(CityBean.class.getName()).log(Level.SEVERE, null, ex);
//        }
        this.name = name;
    }

    /**
     * @return the zipCode
     */
    public String getZipCode() {
        return zipCode;
    }

    /**
     * @param zipCode the zipCode to set
     */
    public void setZipCode(String zipCode) {
//        try {
//            if (zipCode != null) {
//                // this.zipCode = new String(zipCode.getBytes(ConstantManager.ENCODING_ISO88591), ConstantManager.ENCODING_UTF8);
//                this.zipCode = new String(zipCode.getBytes(ConstantManager.ENCODING_UTF8), ConstantManager.ENCODING_UTF8);
//            }
//
//        } catch (UnsupportedEncodingException ex) {
//            Logger.getLogger(CityBean.class.getName()).log(Level.SEVERE, null, ex);
//        }
        this.zipCode = zipCode;
    }

    /**
     * @return the note
     */
    public String getNote() {
        return note;
    }

    /**
     * @param note the note to set
     */
    public void setNote(String note) {
//        try {
//            if (note != null) {
//                this.note = new String(note.getBytes(ConstantManager.ENCODING_ISO88592), ConstantManager.ENCODING_UTF8);
//            }
//
//        } catch (UnsupportedEncodingException ex) {
//            Logger.getLogger(CityBean.class.getName()).log(Level.SEVERE, null, ex);
//        }
        this.note = note;
    }

    /**
     * @return the submit
     */
    public String getSubmit() {
        return submit;
    }

    /**
     * @param submit the submit to set
     */
    public void setSubmit(String submit) {
        this.submit = submit;
    }
}
